<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!--  CDN 链接 引入方法  -->
    <!--  jQuery 文件  -->
    <script src="{{ url_for('static',filename='jquery/jquery.min.js',_external=True) }}">//jQuery</script>
    <!--  Bootstrap 的 CSS 样式文件  -->
    <!--    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">-->
    <link rel="stylesheet" href="{{ url_for('static',filename='bootstrap/bootstrap.min.css',_external=True) }}">
    <!--  Bootstrap 的 JS 文件 (动画效果需要jQuery)  -->
    <!--    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js">// bootstrap </script>-->
    <script src="{{ url_for('static',filename='bootstrap/bootstrap.min.js',_external=True) }}">// bootstrap </script>
    <!--  Vue 文件  -->
    <!--    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.9/vue.min.js"></script>-->
    <script src="{{ url_for('static',filename='vue/vue.min.js',_external=True) }}"></script>
    <!--  以下为 css样式书写区  -->
    <style>
    </style>

</head>
<body>
<div class="container-fluid" style="width: 400px;height: auto">
    <div>
        <h1>房源分析系统用户登陆</h1>
        <div class="container-fluid">
            <div class="form-group ">
                <label for="username"></label>
                <input type="text" id="username" placeholder="请输入用户名" name="username" class="form-control">
            </div>
            <div class="form-group">
                <label for="password"></label>
                <input type="password" id="password" placeholder="请输入密码" name="password" class="form-control">
            </div>
            <div class="text-center">
                <input type="button" class="btn btn-success" value="登陆" id="id_commit">
                <input type="button" class="btn btn-success" value="注册" id="id_register">
                <span style="color: red" id="error_code"></span>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    // 绑定点击事件，提交ajax请求
    $("#id_commit").click(function () {
        $.ajax({
            url: "http://127.0.0.1:7878/user/login",
            type: "post",
            data: {
                "username": $("#username").val(),
                "password": $("#password").val(),
            },
            success: function (result) {
                console.log(result)
                if (result.code === 200) {
                    window.location.href = result.url;
                } else {
                    $("#error_code").text(result.message);
                }
            },
        });
    });

    // 绑定点击事件，提交ajax请求
    $("#id_register").click(function () {
        $.ajax({
            url: "http://127.0.0.1:7878/user/register",
            type: "post",
            data: {
                "username": $("#username").val(),
                "password": $("#password").val(),
            },
            success: function (result) {
                console.log(result)
                if (result.code === 200) {
                    alert(result.message)
                    window.location.reload();
                } else {
                    $("#error_code").text(result.message);
                }
            },
        });
    });
</script>
</html>